等待不可避免,但“加载中”不是一种通用状态。

一次 100ms 的请求如果先闪出一个 Spinner,用户反而感觉页面卡了一下;一个两秒的按钮操作如果让整页变灰,会切断所有其他工作;一段几十秒的导入如果只显示转圈,用户不知道它是在运行、卡住,还是已经失败。

好的等待状态不是让动画填补空白,而是回答三个问题:还要等多久、我在等什么、我能继续做什么。

先按时间决定是否需要加载态

300ms 以内:不要单独出现加载态

短于 300ms 的等待不显示 Spinner、Skeleton 或进度条。它们刚出现就消失,看起来像故障闪烁。

只有一种例外:按钮自身的图标本来就代表动作,例如刷新或同步。点击后,图标直接从按压状态旋转,始终停在完整一圈,不跳到半个角度。

如果结果发生在用户正在看的位置,结果本身就是反馈;如果结果发生在页外,例如后台同步、复制或自动保存,再用短 Toast 确认。

0.3–3 秒:在用户操作的位置响应

一个按钮提交请求时,不要在页面中央盖一层 Loading。

按钮的文字和宽度保持不动,只让图标变化。图标本身没有“等待”含义时,可以等 300ms 后再淡入 Spinner;已经出现过的加载态至少保留 500ms,避免闪现。

按钮在运行期间不能被再次提交,但页面其他区域应该继续可用。完成后恢复按钮,并用一句短 Toast 告知结果。

1–10 秒:Skeleton 或明确的进度

当页面结构已经确定,Skeleton 比空白页和居中 Spinner 更能说明“内容会出现在哪里”。

标题、标签、筛选器和表头这些不依赖数据的部分应该立即显示。300ms 后,再用真实尺寸的占位形状补齐剩余区域:

  • 行高与头像尺寸一致;
  • 文本线略短于真实文本,并保留轻微长度变化;
  • 整组列表共享一条每约 1.2 秒扫过的亮带;
  • 数据到达时,真实行在相同位置依次淡入,每项约间隔 40ms。

核心不是画灰色方块,而是让加载前后的布局完全重合,数据到达时页面不跳动。

超过 10 秒:给进度、阶段和出口

可计数的任务需要说明正在做什么、完成多少、还剩多久。

上传、导入、导出之类的后台工作,应该在用户离开当前页面后继续可见,因此适合放进左上或右上的 Notification 中;只影响当前项目的任务,可以直接在原位置显示同尺寸的进度。

页面继续可用,任务可取消。完成后,进度卡片在原位转成结果,而不是另开一条消息。

无法计数的长任务,至少要说清阶段,例如「正在连接」「正在处理 3 个文件」。超过约 10 秒仍无结果,应提示比预期更久,并提供转到后台的选项。

Spinner 只适合短而未知的动作

Spinner 适合动作范围小、时间未知、结果无需用户处理的等待。

默认图标可以取产品自己的加载图标,尺寸 12–16px,每圈约 0.9 秒。按钮里的动作图标如果本来就代表该操作,可以直接旋转;否则与 Spinner 做约 180ms 的淡入和轻微缩放过渡。

Spinner 不应该同时出现在按钮、页面遮罩和顶部进度条三处。一个等待只保留一个指示器。

Skeleton 不是灰色占位图

Skeleton 的价值在于提前建立布局。

真实尺寸的行、头像、缩略图和文本线决定占位;亮带只是让用户知道内容仍在加载。刷新已有内容时,应保留旧数据并显示轻微刷新状态,而不是突然把可用页面替换成 Skeleton。

如果返回的数据少于占位数量,多出的形状直接淡出;如果更多,新行在列表尾部继续进入。无论哪种情况,已出现的真实内容都不应该跳位。

进度需要比“百分比”更多信息

进度条必须同时提供:

  • 任务名称;
  • 已完成数量或百分比;
  • 有足够样本后显示预计剩余时间;
  • 取消入口;
  • 完成后的原位结果。

在还没有一秒数据时,剩余时间可以显示「正在估算」,不要伪造一个快速变化的数字。任务结束后,进度条收起,图标与标题在同一张卡片内变成完成状态。

卡片应保留在通知中心,用户之后仍能打开结果。屏幕上关闭卡片,不应等于丢掉后台任务。

乐观更新要先能回来

完成、点赞、重命名、排序、移动和评论,几乎总会成功,而且容易恢复,适合乐观更新。

用户点击后,先在所有出现该状态的位置立即更新:勾选、计数、列表顺序和统计数字同时变化。服务器保存放在后台,界面上只显示安静的「保存中」,随后变成「已保存」。

如果保存失败,必须完整撤回:

  • 勾选、计数和列表位置全部恢复;
  • 用户输入的内容保留;
  • 在原项目上说明失败原因;
  • 用 Retry 替换保存状态,直到问题解决。

支付、永久删除、向其他人发送消息等不可轻易撤回的动作,不使用乐观更新。

AI 回复属于流式结果

AI 的长回复不应该用一个覆盖整页的 Spinner。

先展示正在进行的步骤,例如「读取 4 个任务」「检查 3 个事件」「撰写摘要」,每一步完成后变成勾选。随后文字随流到达,当前最后一段从轻微模糊中淡入,并在末尾保留光标。

答案的空间要从一开始就预留好,只向下增长,避免每来一句话都把页面推一下。结束后提供 Copy 与 Retry;只有答案经常很久才完成时,才提供停止。

首段文字最好在 1–2 秒内出现;如果模型还没开始输出,步骤状态必须继续变化,让用户知道工作没有停。

用户不需要看见的等待就不要显示

预取、草稿保存和后台同步通常不需要加载态。

如果必须给一点确认,就使用固定位置的安静状态,例如「已保存」,不要用 Spinner 打断当前任务。

统一的等待规则

无论选择哪种模式,都应共享同一套规则:

  • 300ms 延迟与 500ms 最短显示由同一个 helper 控制;
  • 内容到达时布局不移动,空间提前预留;
  • 一个等待只有一个主指示器;
  • 刷新时优先保留旧数据;
  • 失败留在原位置,说明原因并提供 Retry;
  • 减少动态效果时保留状态,去掉扫光和旋转,可用轻微透明度脉冲或不闪动;
  • 加载区域设置 aria-busy,完成与失败通过礼貌 live region 播报,焦点保持原位,忙碌按钮仍可被键盘到达。

先诊断,再选组件

在改代码前,先找出所有让人等待的位置:

  • 页面与路由加载;
  • 列表和表格;
  • 搜索与筛选;
  • 保存、发送、同步、删除按钮;
  • 上传、导入和导出;
  • 后台任务;
  • AI 调用。

每个位置记录触发方式、典型时长、当前显示、内容到达时是否跳位、是否允许继续操作、失败表现与能否取消。

然后按等待类型分组,先输出一张表:位置、时长与现状、应该使用什么、原因、准备如何改。共享的 delay helper、Skeleton 形状和进度 Notification 也要单独列出,等用户选择后再修改。

检查清单

  • 300ms 以内是否没有单独加载态;
  • 按钮等待是否只改变图标,保持文字与宽度;
  • 加载态是否延迟出现并至少保留 500ms;
  • Skeleton 是否使用真实布局尺寸,数据到达时不跳位;
  • 长任务是否提供进度、阶段、剩余时间、取消和后台继续;
  • 刷新时是否保留旧数据,而不是显示整页 Skeleton;
  • 乐观更新失败是否能完整回滚、保留输入并提供 Retry;
  • AI 回复是否先展示步骤、预留空间并流式出现;
  • 一个等待是否只有一个主指示器;
  • 减少动态效果、读屏、键盘和真实慢网测试是否都通过。

等待状态示例 Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Prompt

Review how my product handles waiting, and decide for each wait which loading state fits: nothing, a spinner, a skeleton, progress, an optimistic change, or an AI answer written as it arrives. Then, if I want it, change them along the lines below. This is about judgment first: diagnose and recommend, and change only what I approve.

This is a change to my product, not a demo. Work inside my code, on my stack, with my components, tokens, motion values and copy style. Do not add a dependency, a data library or a new visual pattern without asking. Every value below is a default to start from.

0. Read the product first
- Find every place a person waits: page and route loads, lists and tables, search and filters, buttons that call the server (save, send, sync, delete), uploads, imports and exports, background jobs, and AI calls.
- For each one, note: what starts it; how long it usually takes (measure it, or estimate from the call: cached, one request, several, a job); what is shown meanwhile (a spinner, a skeleton, nothing, a blocking overlay); whether the layout moves when the data arrives; whether the person can keep working; what happens when it fails; and whether it can be cancelled.
- Find the shared pieces: the spinner, skeleton and progress components, the data layer (a fetch wrapper, React Query, SWR, Apollo, a store), and any global loading bar or overlay.
- Tell me in a few lines what you found before going on.

1. The kinds of waiting
a. Under 300ms: show no separate loader (no spinner, skeleton or bar): one that appears and goes in under 300ms reads as a flicker. The one exception is a button whose own icon already means the action, which turns from the press (b). The result is the feedback: when it shows where the person is looking, nothing more is needed; when it doesn't (a sync, a copy, a save off-screen), confirm it with a short toast.
b. A short wait for one action, length unknown (about 0.3 to 3s): show it where the person acted, with the label and the width unchanged. If the button's icon already means the action (sync, refresh), turn that icon from the press: at least one whole turn even when the answer is instant, and on until the answer lands, always stopping on a whole turn. Otherwise the icon becomes a spinner, started only after 300ms and kept at least 500ms. Block a second press while it runs, but never grey out the page. When it is done, the button goes back as it was and a short toast gives the result (Synced, 1 task updated): at the top centre, a few words, gone after about 3s.
c. Content whose layout is known (a page, a list, a card, a table): a skeleton.
- Show what does not depend on the data at once: the title, tabs, filters, column headers.
- After 300ms, draw skeleton shapes for the rest, at the real sizes and places: the same row height and avatar size, lines a little shorter than the text, their lengths varying a little.
- A light band crosses the whole list together, every 1.2s.
- When the data arrives, the real rows take the same places, top to bottom, each fading in over 200ms, 40ms apart. Nothing jumps. If fewer rows come back, the extra shapes fade out.
- Never put a lone spinner in the middle of an empty page instead.
d. Long work that can be counted (uploads, imports, exports, batch jobs, over about 3s): progress.
- Say what it is doing, how far (a count or a percentage, and a bar), and the time left once there is a second of data to estimate from; before that, "Estimating…".
- Show it in a notification at the top right when the work goes on while the person moves on (an import, an export, a batch job): it keeps the page free, stays on every page and is kept until handled. Work that only concerns one item can show in that item's place instead, at the same size, so nothing on the page moves.
- Keep the page usable and offer Cancel. If it can go on without the person, let it run in the background and tell them when it is done.
- Show it once the work has run 300 to 500ms; a job done sooner needs only the result.
- At the end it turns into the result in place, and opens it when clicked.
- Long work that cannot be counted: name the stage it is in (Connecting, Processing 3 files) rather than an endless spinner; after about 10s, say it is taking longer than usual and offer to keep it running in the background.
e. An action that almost always works and is easy to reverse (mark done, like, rename, reorder, move, add a comment): optimistic.
- Show the result at once, before the server answers, everywhere it appears (the tick, the status, the totals), and save behind it. Say quietly that it is saving, in a fixed place on the item (Saving, then Saved, fading after a moment), never with a spinner over the change itself.
- If the save fails, put every part of the change back, say why on the item in a few words (Couldn’t save), and offer Retry in the place of the saving status. Keep what the person typed.
- Not for payments, deleting for good, sending something to other people, or anything that cannot be quietly put back.
f. AI answers and other results that arrive in pieces:
- First say what it is doing, as steps (Reading 4 tasks, Checking 3 events, Writing the summary), each turning into a check.
- Then write the answer as the words arrive, each fading in from a slight blur as the next begins, with a caret after the last.
- Keep the answer's space from the start (a card at its final size, or a minimum height that only grows downward), so the page does not move as it writes.
- At the end, show Copy and Retry. Offer a way to stop only when answers often run long.
- Aim for the first words within 1 to 2s; when that is not possible, the steps must keep moving.
g. Waits the person does not need to see (prefetching, saving a draft, syncing in the background): nothing, or a quiet status in a fixed place (Saved). Never block the page for them.

2. Rules for every kind
- Thresholds: under 300ms nothing but a button's own icon turning; 300ms to 1s a spinner or skeleton; 1 to 10s a skeleton, or progress that says what it is doing; over 10s progress, the time left and a way out. Measure on a slow mobile network, not on localhost.
- Delay and minimum: what appears after 300ms stays at least 500ms. Write one helper for this and use it everywhere.
- The layout never moves when content arrives: reserve the space (skeletons at real size, minimum heights, fixed image ratios).
- One indicator per wait: never a spinner on the button, an overlay on the page and a bar at the top all at once.
- Keep what is known: when refreshing, keep showing the old data with a quiet refresh state, rather than a skeleton.
- Failures stay where they happened, say what failed and what to do, and offer Retry. A toast that disappears is not enough for something the person has to fix.
- Reduced motion: keep every state; drop the moving band and the spin, and use a soft opacity pulse or nothing.
- Accessibility: aria-busy on the region that is loading, a polite live region for done and failed, focus left where it was, and a busy button still reachable by keyboard.

3. Report before changing anything
Give me a table first, and do not change code yet. One row per wait:
- Where: the screen or component, and what starts the wait.
- Now: how long it takes, and what is shown.
- Should be: nothing, spinner, skeleton, progress, optimistic, AI answer, or background; and why, in a phrase that points to the rule above.
- Change: what you would do, in a phrase.
Group the rows by kind. Then list the shared pieces you would add or change (the delay helper, skeleton shapes, the progress notification). Wait for me to choose what to change.

4. How it looks (defaults; fit them to my design)
- Spinner: the loading icon from my icon set (or a ring segment on a faint track), 12 to 16px, a turn every 0.9s, in the accent or the text colour. In a button, an icon that already means the action turns instead, speeding up over the first 18% and slowing over the last 18% so it starts and stops at rest: one turn in 640ms at the least, and on at about 600° a second for longer waits (three turns in 1.7s), always ending on a whole turn; otherwise the icon cross-fades into the spinner over 180ms with a little blur and scale. The label and width stay.
- Toast: 40px tall with a 16px corner, a check on a soft tile and a few words, top centre of the content; it comes down 10px from a slight blur over 500ms, and leaves after about 3s.
- Skeleton: shapes in the raised grey (rgb(240 240 242) on white; on dark, white at 8%), 6px corners for lines, circles for pictures, 12px lines for 14px text. The band is white at 75%, 320px wide, crossing the whole list at once.
- Progress in a notification: 344px wide, 24px corners, 14px padding (16px on the right), at the top right. A 32px icon tile centred on the words beside it, holding the file's type as a two-tone filled icon at 18px, the title (Importing tasks.csv), the count and time left in one line (568 of 1,240 rows · About 2s left), and a 4px bar in the accent on the accent at 10%; no row of buttons: the card opens what it is about, and a close mark on hover cancels. It comes down 56px onto the page out of a 4px blur and from 96% over 420ms. When it is done, the same card changes in place: the old words blur out over 160ms and the new ones in over 420ms (Imported 1,240 tasks, Added to Backlog.), the bar folds away and the tile turns solid green with a heavy white check, the same 18px. It then stays until opened or closed.
- Optimistic: a 20px checkbox in the task icon's place, shown on hover and filled green when ticked; totals roll to the new figure over 320ms; Saving with a 12px spinner, then Saved with a check, at the start of the row's last column, in 12px grey. When a save fails the row shakes 6px, twice, over 360ms, the reason in red takes the place of the row's counts, and Retry takes the place of Saving, until it is fixed.
- AI answer: steps at 13px with a 16px spinner that turns into a check; the answer at 15/24; the caret 2px wide in the accent; Retry and Copy at the end.

5. How to build it, by platform
These are suggestions; check them against my stack and its versions, and prefer what the product already uses.
- Web: the delay and minimum as one hook or helper, for example useDelayedFlag(loading, 300, 500). React: Suspense with a skeleton fallback, startTransition to keep the old content while the new loads, useOptimistic or a mutation's onMutate with a rollback; React Query or SWR keep the previous data while they refetch. Read streamed answers from fetch with a ReadableStream, or the AI SDK's useChat. Draw the band as one gradient fixed to the list, moved by background-position, and stop it under prefers-reduced-motion.
- iOS: .redacted(reason: .placeholder) for skeletons, ProgressView for progress, Task cancellation for Cancel, optimistic changes in the view model with a rollback, AsyncSequence for streamed text.
- Android: a shimmer brush over placeholder shapes in Compose, LinearProgressIndicator with a value, Paging's LoadState for lists, optimistic state in the ViewModel with a rollback, Flow for streamed text.
- Flutter: the real widgets as placeholders under a shimmer (or Skeletonizer), LinearProgressIndicator(value:), a Stream for streamed text.
- Rust and other native desktops (egui, iced, GPUI, Tauri): the same states in the UI model, with the 300 and 500ms timers in the update loop.

6. Check
- Throttle the network (Slow 4G) and time every wait: nothing shows a separate loader under 300ms, nothing flashes, nothing moves the layout when the data comes.
- Turn the network off during an optimistic change: it goes back, says why, and Retry works.
- Cancel a long job, and leave the page during one: nothing is lost, nothing keeps spinning.
- A screen reader hears loading and done; reduced motion has no moving band; light and dark both checked; existing tests still pass.

质感来自可解释的细节

加载状态不是在页面空着的时候塞一个动画,而是让用户知道时间正在被怎么使用。

短等待不打断,熟布局不跳动,长任务有进度和出口,乐观更新能回来,流式结果先说明正在做什么。等待仍然存在,但用户不会因为不知道发生什么而失去耐心。

站内搜索

没有找到内容!